require(['init'], function () {
  var $pagination = $('#js-pagination');
  var pagination;

  function getFeedbackList(querystr, cb) {
    var url = '/api/comment/students';
    var query = {}
    if(querystr) {
      query = querystr
    }
    ajaxMethod({
      url: url,
      data: query,
      success: function (data, status) {
        cb && cb(data)
        console.log(data)
        if(status.code == 0) {
          if(data.list.length == 0) {
            $('#J_feedbacklist').html('<div style="margin-top: 50px;text-align: center;">'+i18next.t('input.nullresults')+'</div>');
            $pagination.hide()
            return;
          }
          var $feedbackList = $('#J_feedbacklist').html('')
          var $thead = $('<thead>\
            <tr>\
             <th>'+i18next.t('table.no')+'</th>\
             <th>'+i18next.t('info.studentname')+'</th>\
             <th>'+i18next.t('info.studentphone')+'</th>\
             <th>'+i18next.t('table.coursename')+'</th>\
             <th>'+i18next.t('table.lessonsname')+'</th>\
             <th>'+i18next.t('table.schooltime')+'</th>\
             <th>'+i18next.t('table.starrating')+'</th>\
             <th>'+i18next.t('table.rewardnumber')+'</th>\
             <th>'+i18next.t('table.teacherevaluation')+'</th>\
            </tr>\
          </thead>').appendTo($feedbackList)


         /* if(!data.length) {
            $feedbackList.parent().append('<div style="margin-top:50px;text-align:center">无结果</div>')
            return
          }*/

          var $tbody = $('<tbody></tbody>').appendTo($feedbackList)
          $.each(data.list, function (i, item) {
            var $tr = $('<tr></tr>')
            $tr.append('<td>'+(i+1)+'</td>')
            $tr.append('<td>'+ (item.name||'') +'</td>')
            $tr.append('<td>'+ (item.mobile||'') +'</td>')
            $tr.append('<td>'+ (item.course||'') +'</td>')
            $tr.append('<td>'+ item.schedule +'</td>')
            $tr.append('<td>'+ item.begintime +'</td>')
            $tr.append('<td>'+ (item.star_level+''+i18next.t('table.star')+'') +'</td>')
            $tr.append('<td>'+ item.class_status +'</td>')
            $tr.append('<td>'+ item.comment +'</td>')

            $tbody.append($tr)
          });
          $pagination.show();
        }
      }
    })
  }
  function loadSearchData(querystr) {
    if(querystr) {
      pagination.filter.name = querystr;
      pagination.filter.schedule = querystr;
      pagination.filter.course = querystr;
      pagination.filter.mobile = querystr;

      pagination.searchData()
    } else {
      pagination.reloadData()
    }
  }

  $('#J_feedback_search').on('click', function() {
    var $input = $(this).prev();
    var querystr = $.trim($input.val());
    loadSearchData(querystr)
  })

  $('.searchInput').on('keyup', function(e) {
    if(e.keyCode == 13) {
      var querystr = $.trim($(this).val());
      loadSearchData(querystr)
    }
  })

  pagination = new Pagination($pagination, getFeedbackList)

})
